package com.tour.controller;

import com.tour.config.ResponseWrapper;
import com.tour.entity.Collection;
import com.tour.service.impl.CollectionServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2020-12-30
 */
@Api(tags = "收藏景区管理")
@RestController
@RequestMapping("/app/collection")
public class CollectionController {

    @Autowired
    CollectionServiceImpl collectionService;

    @ApiOperation("收藏景区")
    @PostMapping("/addCollection")
    public ResponseWrapper addCollection(@RequestBody Collection collection){
        ResponseWrapper wrapper = collectionService.addCollection(collection);
        return wrapper;
    }
    @ApiOperation("查看是否收藏该景区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户id"),
            @ApiImplicitParam(name = "scenicId",value = "景区id")
    })
    @GetMapping("/isCollection")
    public ResponseWrapper isCollection(@RequestParam(name = "userId")Integer userId,
                                        @RequestParam(name = "scenicId")Integer scenicId){
        ResponseWrapper wrapper = collectionService.isCollection(userId,scenicId);
        return wrapper;
    }
    @ApiOperation("取消收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户id"),
            @ApiImplicitParam(name = "scenicId",value = "景区id")
    })
    @DeleteMapping("/delCollection")
    public ResponseWrapper delCollection(@RequestParam(name = "userId")Integer userId,
                                         @RequestParam(name = "scenicId")Integer scenicId){
        ResponseWrapper wrapper = collectionService.delCollection(userId,scenicId);
        return wrapper;
    }
    @ApiOperation("查询某个人的收藏的所有景区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户id"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/findAllCollection")
    public ResponseWrapper findAllCollection(@RequestParam(name = "userId")Integer userId,
                                             @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                             @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = collectionService.findAllCollection(userId,pageNum,pageSize);
        return wrapper;
    }
}

